package ru.reaperoq.taskmanager.models

import jakarta.persistence.*

@Entity(name = "files")
class File(
    @Id @GeneratedValue(strategy = GenerationType.SEQUENCE)
    val id: Long? = null,
    @Column(nullable = false, updatable = false)
    val data: ByteArray,
    @Column(nullable = false, updatable = false, length = 256)
    val mimeType: String,

    @ManyToMany
    @JoinTable(
        name = "files_to_tasks",
        joinColumns = [(JoinColumn(name = "file_id", referencedColumnName = "id"))],
        inverseJoinColumns = [(JoinColumn(name = "task_id", referencedColumnName = "id"))],
    )
    val tasks: Set<Task> = emptySet(),

    @ManyToMany
    @JoinTable(
        name = "user_files",
        joinColumns = [(JoinColumn(name = "file_id", referencedColumnName = "id"))],
        inverseJoinColumns = [(JoinColumn(name = "user_id", referencedColumnName = "id"))],
    )
    val users: Set<User> = emptySet(),
) {
}